package wetalk.software.bupt.com.wetalk.util;

import java.util.Comparator;

import wetalk.software.bupt.com.wetalk.model.po.Group;

/**
 * Created by Administrator on 2017/11/30.
 */

public class GroupPinyinComparator implements Comparator{
    public GroupPinyinComparator(){

    }

    @Override
    public int compare(Object o1, Object o2) {//首字母相同，正常比较；首字母不同，转为小写再比较
        Group group1 = (Group) o1;
        Group group2 = (Group) o2;
        MyPinyinParser pinyinParser=new MyPinyinParser();
        String py1=pinyinParser.toComplexPy(group1.getGroup_name());
        String py2=pinyinParser.toComplexPy(group2.getGroup_name());
        if(py1.charAt(0)<65 || (py1.charAt(0)>90 && py1.charAt(0)<97) || py1.charAt(0)>122 ){
            return 1;
        }
        if(py2.charAt(0)<65 || (py2.charAt(0)>90 && py2.charAt(0)<97) || py2.charAt(0)>122 ){
            return -1;
        }
        String smallPy1=py1.substring(0).toLowerCase();
        String smallPy2=py2.substring(0).toLowerCase();
        if(smallPy1.equals(smallPy2)){
            return py1.compareTo(py2);
        }else{
            return smallPy1.compareTo(smallPy2);
        }
    }
//    @Override
//    public int compare(Object arg0, Object arg1) {
//         //按照名字排序
//        Group group0 = (Group) arg0;
//        Group group1 = (Group) arg1;
//        String catalog0 = "";
//        String catalog1 = "";
//
//        if (group0 != null && group0.getGroup_name() != null
//                && group0.getGroup_name().length() > 1)
//            catalog0 = PinYinUtil.converterToFirstSpell(group0.getGroup_name())
//                    .substring(0, 1);
//
//        if (group1 != null && group1.getGroup_name() != null
//                && group1.getGroup_name().length() > 1)
//            catalog1 = PinYinUtil.converterToFirstSpell(group1.getGroup_name())
//                    .substring(0, 1);
//        int flag = catalog0.compareTo(catalog1);
//        return flag;
//
//    }
//        @Override
//        public int compare (Object o1, Object o2){
//            Group group1 = (Group) o1;
//            Group group2 = (Group) o2;
//            MyPinyinParser pinyinParser = new MyPinyinParser();
//            String py1 = pinyinParser.toComplexPy(group1.getGroup_name());
//            String py2 = pinyinParser.toComplexPy(group2.getGroup_name());
//            if (py1.charAt(0) < 65 || (py1.charAt(0) > 90 && py1.charAt(0) < 97) || py1.charAt(0) > 122) {
//                return 1;
//            }
//            return py1.compareTo(py2);
//        }
    }


